/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.workflow.service.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Splitter;
import com.google.gson.Gson;
import com.koron.workflow.bean.MessageEntity;
import com.koron.workflow.bean.TaskListBean;
import com.koron.workflow.service.api.WorkflowService;
import com.koron.workflow.util.HttpRequestGetAndPostUtil;
import com.koron.workflow.util.SecretUtil;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.swan.bean.MessageBean;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.*;

@Service
@PropertySource({ "classpath:workflow.properties" })
public class WorkflowServiceImpl implements WorkflowService {

	private final static Logger logger= LoggerFactory.getLogger(WorkflowServiceImpl.class);
	@Value("${workflow.appCode}")
    private String appCode;

	private List<Integer> operations = new ArrayList<Integer>() {
        {
            // 1驳回、2转办、4添加沟通人、8催办、16废弃、32通过、64 添加沟通/评论信息、128取消沟通
            this.add(1);
            this.add(2);
            this.add(4);
            this.add(8);
            this.add(16);
            this.add(32);
            this.add(64);
            this.add(128);
        }
    };

	@Override
	public MessageBean<?> start(String setCode, String processCode, String billId, String operator, String title,
			String comment,String formVariables, String otherNodeCandidates, String attachment) throws Exception {
		Objects.requireNonNull(setCode);
        Objects.requireNonNull(processCode);
        Objects.requireNonNull(title);
        Objects.requireNonNull(billId);
        Objects.requireNonNull(operator);
        Objects.requireNonNull(formVariables);

        Map params = new Hashtable();
        params.put("secret", SecretUtil.encrypt(this.appCode));
        params.put("setCode", setCode);
        params.put("processCode", processCode);
        params.put("billId", billId);
        params.put("operator",operator);
        params.put("title",title);
        Optional.ofNullable(comment).ifPresent(str -> params.put("comment",comment));
        params.put("formVariables", new Gson().fromJson(formVariables, Map.class));
        Optional.ofNullable(otherNodeCandidates).ifPresent(str -> params.put("otherNodeCandidates", otherNodeCandidates));
        Optional.ofNullable(attachment).ifPresent(str -> params.put("attachment",attachment));
        String ret = HttpRequestGetAndPostUtil.sendPost(workflow_url + workflowStartUrl, JSON.toJSONString(params));
        return objectMapper.readValue(ret, MessageBean.class);
	}


	@Override
	public String view(String setCode, String processCode, String operator, String taskId,
			String approverUserAccound,String processInstanceId) throws Exception {
		Objects.requireNonNull(setCode);
        Objects.requireNonNull(processCode);
        Objects.requireNonNull(operator);
        Map params = new Hashtable();
        params.put("secret", SecretUtil.encrypt(this.appCode));
        params.put("setCode", setCode);
        params.put("processCode", processCode);
        params.put("operator",operator);
        if (!StringUtils.isBlank(taskId) && !StringUtils.isBlank(approverUserAccound)) {
            List<String> accounds = Splitter.on("|").trimResults().omitEmptyStrings().splitToList(approverUserAccound);
            List<String> taskIds = Splitter.on("|").trimResults().omitEmptyStrings().splitToList(taskId);
            for (int i = 0, size = accounds.size(); i < size; i++) {
                if (Splitter.on(",").trimResults().omitEmptyStrings().splitToList(accounds.get(i)).contains(operator)) {
                    params.put("taskId", taskIds.get(i >= taskIds.size() ? taskIds.size() - 1 : i));
                    break;
                }
            }
        }
        Optional.ofNullable(processInstanceId).ifPresent(id -> params.put("processInstanceId", id));
        String ret = HttpRequestGetAndPostUtil.sendGet(workflow_url + workflowViewUrl, params);
        return ret;
	}

	public String appView(String setCode, String processCode, String operator,String taskId,
					   String approverUserAccound,String processInstanceId) throws Exception {
		Objects.requireNonNull(setCode);
		Objects.requireNonNull(processCode);
		Objects.requireNonNull(operator);
		Map params = new Hashtable();
		params.put("secret", SecretUtil.encrypt(this.appCode));
		params.put("setCode", setCode);
		params.put("processCode", processCode);
		params.put("operator", operator);
		if (!StringUtils.isBlank(taskId) && !StringUtils.isBlank(approverUserAccound)) {
			List<String> accounds = Splitter.on("|").trimResults().omitEmptyStrings().splitToList(approverUserAccound);
			List<String> taskIds = Splitter.on("|").trimResults().omitEmptyStrings().splitToList(taskId);
			for (int i = 0, size = accounds.size(); i < size; i++) {
				if (Splitter.on(",").trimResults().omitEmptyStrings().splitToList(accounds.get(i)).contains(operator)) {
					params.put("taskId", taskIds.get(i >= taskIds.size() ? taskIds.size() - 1 : i));
					break;
				}
			}
		}
		Optional.ofNullable(processInstanceId).ifPresent(id -> params.put("processInstanceId", id));
		String ret = HttpRequestGetAndPostUtil.sendGet(workflow_url + appWorkflowViewUrl, params);
		return ret;
	}


	@Override
	public MessageBean<?> submit(String setCode, String processCode, String billId, String operator, String taskId,
			String approverUserAccound,String comment, Integer operation, String rejectNodeCode, String relatedUser, String formVariables,
			String otherNodeCandidates, String attachment) throws Exception {
		Objects.requireNonNull(billId);
        Objects.requireNonNull(operator);
        Objects.requireNonNull(operation);
        Objects.requireNonNull(taskId);
        if (!this.operations.contains(operation)) {
            return MessageBean.create(-1, "操作类型只能为1驳回、2转办、4添加沟通人、8催办、16废弃、32通过、64 添加沟通/评论信息、128取消沟通", void.class);
        }
        if (operation == 1 && StringUtils.isEmpty(rejectNodeCode)) {
            return MessageBean.create(-1, "请选择驳回节点", void.class);
        }
        if ((operation == 2 || operation == 4) && StringUtils.isEmpty(relatedUser)) {
            return MessageBean.create(-1, "请选择办理人员", void.class);
        }
        Map formMap = new HashMap();
        if (!StringUtils.isEmpty(formVariables)) {
        	formMap = (Map) JSON.parse(formVariables);
        }
        Map params = new Hashtable();
        params.put("secret", SecretUtil.encrypt(this.appCode));
        params.put("setCode", setCode);
        params.put("processCode", processCode);
        params.put("billId", billId);
        params.put("operator", operator);
        params.put("taskId", taskId);
        Optional.ofNullable(comment).ifPresent(str -> params.put("comment", comment));
        params.put("operation", operation);
        Optional.ofNullable(rejectNodeCode).ifPresent(str -> params.put("rejectNodeCode", rejectNodeCode));
        Optional.ofNullable(relatedUser).ifPresent(str -> params.put("relatedUser", relatedUser));
        params.put("formVariables", formMap);
        Optional.ofNullable(otherNodeCandidates).ifPresent(str -> params.put("otherNodeCandidates",otherNodeCandidates));
        Optional.ofNullable(attachment).ifPresent(str -> params.put("attachment", attachment));

        String ret = HttpRequestGetAndPostUtil.sendPost(workflow_url + workflowSubmitUrl, JSON.toJSONString(params));
        return objectMapper.readValue(ret, MessageBean.class);
	}

	@Override
	public MessageBean<?> history(String setCode, String processCode, String billId) throws Exception {
		Map<String, String> params = new Hashtable<>();
        params.put("secret", SecretUtil.encrypt(this.appCode));
        params.put("setCode", setCode);
        params.put("processCode", processCode);
        params.put("billId", billId);
        String ret = HttpRequestGetAndPostUtil.sendGet(workflow_url + workflowHistoryUrl, params);
		return objectMapper.readValue(ret, MessageBean.class);
	}

	@Override
	public String appHistory(String setCode, String processCode, String processInstanceId ) throws Exception {
		Map<String, String> params = new Hashtable<>();
		params.put("secret", SecretUtil.encrypt(this.appCode));
		params.put("setCode", setCode);
		params.put("processCode", processCode);
		params.put("processInstanceId", processInstanceId );
		String ret = HttpRequestGetAndPostUtil.sendGet(workflow_url + appWorkflowHistoryUrl, params);
		return ret;
	}


	@Override
	public MessageEntity<?> list(String setCode, String processCode, String billId, String title, String startDate,
			String endDate, Integer type, Integer status, String operator, Integer page, Integer pageCount)
			throws Exception {
		Map<String, Object> params = new LinkedHashMap<>();
        params.put("secret", SecretUtil.encrypt(this.appCode));
        if (StringUtils.isNotEmpty(setCode)) {
            params.put("setCode", setCode);
        }
        if (StringUtils.isNotEmpty(processCode)) {
            params.put("processCode", processCode);
        }
        if (StringUtils.isNotEmpty(billId)) {
            params.put("billId", billId);
        }
        if (StringUtils.isNotEmpty(title)) {
            params.put("title", title);
        }
        if (StringUtils.isNotEmpty(startDate)) {
            params.put("startDate", startDate);
        }
        if (StringUtils.isNotEmpty(endDate)) {
            params.put("endDate", endDate);
        }
        if (status != null) {
            params.put("status", status);
        }
        Optional.ofNullable(type).ifPresent(str -> params.put("type", str));
        params.put("page", page);
		params.put("pageCount", pageCount);
		params.put("operator", operator);
		String ret = HttpRequestGetAndPostUtil.sendGet(workflow_url + workflowListUrl, params);
		return objectMapper.readValue(ret, MessageEntity.class);
	}




	@Value("${workflow_url}")
	private String workflow_url;

	@Value("${workflow_secret}")
	private String workflow_secret;

	//流程启动接口
	private final String workflowStartUrl = "/process/start.htm";

	//获取操作界面
	private final String workflowViewUrl = "/process/view.htm";

	//流程处理
	private final String workflowSubmitUrl = "/process/submit.htm";
	//流程轨迹
	private final String workflowHistoryUrl = "/process/history.htm";
	//流程模板信息
	private final String workflowListUrl = "/process/list.htm";
	//流程模板信息
	private final String workflowDefineUrl = "/process/define.htm";

	//移动端审批历史端接口
	private final String appWorkflowHistoryUrl="/mobile/historyView.htm";

	//移动端审批表单接口
	private final String appWorkflowViewUrl="/mobile/approvalView.htm";

	/*@Autowired
	private RoleService roleService;*/

	/**
	 * 通过
	 */
	public final Integer OPERATION_PASS = 1;

	private ObjectMapper objectMapper = new ObjectMapper();
	/**
	 * b)获取工作流模板列表
	 */
	private final String TEMPLATE_MAPPING = "/port/template.htm";
	/**
	 * c)获取工作流列表
	 */
	private final String WORKFLOW_MAPPING = "/port/workflow.htm";
	/**
	 * e)工作流办理推送数据
	 */
	private final String SUBMIT_MAPPING = "/port/workflowsubmit.htm";
	/**
	 * f)工作流图表
	 */
	private final String SVG_MAPPING = "/port/workflowsvg.htm";
	/**
	 * g)工作流提交前所需要表单
	 */
	private final String SUBMITPRE_MAPPING = "/port/workflowsubmitpre.htm";
	/**
	 * h)启动工作流实例
	 */
	private final String CREATE_PROCESS_MAPPING = "/port/startProcessInstance.htm";
	/**
	 * i)节点信息
	 */
	private final String NODEINFO_MAPPING = "/port/workflowNodeInfo.htm";

	// 工作流审批历史
	private final String WORKFLOW_HISTORY = "/port/workflowhistory.htm";


	// type 1我发起的 2待审 3参与的 4沟通 5结束
	@Override
	public MessageEntity<List<TaskListBean>> getWorkflowList(String staffcode, Integer type, String templateKey,
			Integer page, Integer pagecount) throws Exception {
		Assert.notNull(staffcode, "[Assertion failed] - this staffcode argument is required; it must not be null");
		Assert.notNull(type, "[Assertion failed] - this type argument is required; it must not be null");
		StringBuffer sb = new StringBuffer();
		sb.append("secret=").append(workflow_secret);
		if (StringUtils.isNotBlank(templateKey)) {
			sb.append("&templatekey=").append(templateKey);
		}
		sb.append("&type=").append(type).append("&staffcode=").append(staffcode);
		sb.append("&page=").append(page).append("&pagecount=").append(pagecount);
		String ret = sendGet(workflow_url + WORKFLOW_MAPPING, sb.toString());
		return objectMapper.readValue(ret, objectMapper.getTypeFactory().constructParametricType(MessageEntity.class,
				objectMapper.getTypeFactory().constructParametricType(List.class, TaskListBean.class)));
	}


	public MessageEntity<?> submitWorkflows(String selfStaffcode, String taskId, Integer operation, String comment,
			String lastTaskId, String userCodes, Map<String, Object> form,String nextCandidateUsers) throws Exception {
		Assert.notNull(selfStaffcode, "[Assertion failed] - this staffcode argument is required; it must not be null");
		Assert.notNull(operation,
				"[Assertion failed] - this bean.get__operation argument is required; it must not be null");
		Assert.notNull(taskId, "[Assertion failed] - this bean.getTaskid argument is required; it must not be null");
		StringBuffer sb = new StringBuffer();
		sb.append("secret=").append(workflow_secret).append("&staffcode=").append(selfStaffcode);
		sb.append("&operation=").append(operation).append("&taskid=").append(taskId);
		sb.append("&comment=").append(comment);
		if (form != null && form.size() > 0) {
			sb.append("&formstr=").append(objectMapper.writeValueAsString(form));
		}
		if(StringUtils.isNotBlank(nextCandidateUsers)){
			sb.append("&nextCandidateUsers=").append(nextCandidateUsers);
		}
		// operation为1时 subinfo为nodekey,
		if (operation == 1 && StringUtils.isBlank(lastTaskId)) {
			throw new Exception("subinfo parameter error");
		}
		sb.append("&subinfo=").append(lastTaskId);
		// operation为2,4 时该参数必须有,该参数为user数组，
		if ((operation == 2 || operation == 4) && StringUtils.isBlank(userCodes)) {
			throw new Exception("subuser parameter error");
		}
		sb.append("&subuser=").append(userCodes);
		logger.info(sb.toString());
		String ret = sendPost(workflow_url + SUBMIT_MAPPING, sb.toString());
		return objectMapper.readValue(ret, MessageEntity.class);
	}

	@Override
	public String workflowPresubmit(String staffcode, String templateKey, String taskId, String processInstId)
			throws Exception {
		Assert.notNull(templateKey, "[Assertion failed] - this templateKey argument is required; it must not be null");
		Assert.notNull(taskId, "[Assertion failed] - this taskId argument is required; it must not be null");
		StringBuffer sb = new StringBuffer();
		sb.append("secret=").append(workflow_secret).append("&staffcode=").append(staffcode).append("&template=")
				.append(templateKey).append("&taskid=").append(taskId);
		if (StringUtils.isNotBlank(processInstId)) {
			sb.append("&processinst=").append(processInstId);
		}
		return sendPost(workflow_url + SUBMITPRE_MAPPING, sb.toString());
	}

	@Override
	public String grabHistory(String workflowInstanceId) throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("secret=").append(workflow_secret);
		sb.append("&procInstId=").append(workflowInstanceId);
		return sendPost(workflow_url + WORKFLOW_HISTORY, sb.toString());
	}

	@Override
	public MessageEntity<HashMap<String, Object>> workflowNodeInfo(String templateKey, String taskId) throws Exception {
		Assert.notNull(templateKey, "[Assertion failed] - this templateKey argument is required; it must not be null");
		StringBuffer sb = new StringBuffer();
		sb.append("secret=").append(workflow_secret).append("&template=").append(templateKey).append("&taskid=")
				.append(taskId);
		String ret = sendPost(workflow_url + NODEINFO_MAPPING, sb.toString());
		return objectMapper.readValue(ret, objectMapper.getTypeFactory().constructParametricType(MessageEntity.class,
				objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class)));
	}

	private String sendGet(String url, String param) {
		String result = "";
		BufferedReader in = null;
		try {
			String urlNameString = url + "?" + param;
			URL realUrl = new URL(urlNameString);
			// 打开和URL之间的连接
			URLConnection connection = realUrl.openConnection();
			// 设置通用的请求属性
			connection.setRequestProperty("accept", "*/*");
			connection.setRequestProperty("connection", "Keep-Alive");
			connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			// 建立实际的连接
			connection.connect();
			// 获取所有响应头字段
			Map<String, List<String>> map = connection.getHeaderFields();
			// 遍历所有的响应头字段
			for (String key : map.keySet()) {
				logger.info(key + "--->" + map.get(key));
			}
			// 定义 BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
		} catch (Exception e) {
			logger.error("发送GET请求出现异常！"+e.getMessage());
		}
		// 使用finally块来关闭输入流
		finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * 向指定 URL 发送POST方法的请求
	 *
	 * @param url
	 *            发送请求的 URL
	 * @param param
	 *            请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
	 * @return 所代表远程资源的响应结果
	 */
	private String sendPost(String url, String param) {
		PrintWriter out = null;
		BufferedReader in = null;
		String result = "";
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			URLConnection conn = realUrl.openConnection();
			// 设置通用的请求属性
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			// 发送POST请求必须设置如下两行
			conn.setDoOutput(true);
			conn.setDoInput(true);
			// 获取URLConnection对象对应的输出流

			out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8));
			// 发送请求参数
			out.print(param);
			// flush输出流的缓冲
			out.flush();
			// 定义BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
		} catch (Exception e) {
			logger.error("发送 POST 请求出现异常！" + e.getMessage());
		}
		// 使用finally块来关闭输出流、输入流
		finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return result;
	}

	/*private String operate(List<Map<String, String>> nodeOperator, List<Map<String, String>> mnodeOperator) {
		Map<String, String> njo = new HashMap<>();
		if ((mnodeOperator != null && mnodeOperator.size() > 0) || (nodeOperator != null && nodeOperator.size() > 0)) {
			mnodeOperator.removeAll(nodeOperator);
			mnodeOperator.addAll(nodeOperator);
			for (Map<String, String> el : mnodeOperator) {
				for (Map.Entry<String, String> entity : el.entrySet()) {
					if (StringUtils.isEmpty(entity.getValue())) {
						continue;
					}
					//njo.put(entity.getKey(), StringUtils.join(split(entity.getValue()), "-"));
				}
			}
		}
		if (njo == null || njo.size() == 0)
			return null;
		try {
			return objectMapper.writeValueAsString(njo);
		} catch (IOException e) {
		}
		return null;
	}*/

	/*private List<String> split(String users) {
		List<String> list = new ArrayList<>();
		if (users == null)
			return list;
		try (SessionFactory factory = new SessionFactory()) {
			DepartmentMapper staff = factory.getMapper(DepartmentMapper.class);
			String[] userArray = users.split(",");
			for (String user : userArray) {
				if (user.startsWith("1-"))
					list.add(user.substring(2));
				else if (user.startsWith("2-")) {
					List<StaffInfoBean> info = staff.getStaffOfDemartment(user.substring(2));
					List<String> depts = info.stream().map((item) -> item.getLoginid()).collect(Collectors.toList());
					list.addAll(depts);
				}
			}
		}
		return new ArrayList<String>(new HashSet<>(list));
	}

	@Override
	public MessageEntity<?> startApproval(SafetyUser signinUser, String id) {
		// TODO Auto-generated method stub
		SessionFactory factory = new SessionFactory();
		MessageEntity<?> msg = new MessageEntity<>();
		try {
			SafetyTaskMapper safetyTaskMapper = factory.getMapper(SafetyTaskMapper.class);
			SafetyTask task = safetyTaskMapper.queryOne(id);
			if (task == null) {
				msg.setCode(BusinessCode.CANNOT_START_TASK_NULL.getCode());
				msg.setDescription(BusinessCode.CANNOT_START_TASK_NULL.getDescription());
				return msg;
			} else {
				Integer state = task.getState();
				if (!(0 == state)) {
					msg.setCode(BusinessCode.CANNOT_START_TASK_STARTED.getCode());
					msg.setDescription(BusinessCode.CANNOT_START_TASK_STARTED.getDescription());
					return msg;
				}
				if (beginBusinessFlow(signinUser, task, safetyTaskMapper, new HashMap<>())) {
					msg.setCode(BusinessCode.SUCCESS.getCode());
					msg.setDescription(BusinessCode.SUCCESS.getDescription());
					factory.close(true);
					return msg;
				}
			}
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			factory.close(false);
			msg.setCode(BusinessCode.SYSTEM_ERROR.getCode());
			msg.setDescription(BusinessCode.SYSTEM_ERROR.getDescription());
			return msg;
		}
		msg.setCode(BusinessCode.SYSTEM_ERROR.getCode());
		msg.setDescription(BusinessCode.SYSTEM_ERROR.getDescription());
		return msg;
	}

	@Override
	public boolean beginBusinessFlow(SafetyUser signinUser, SafetyTask task, SafetyTaskMapper safetyTaskMapper,
			Map<String, Object> parameterMap) {
		try {
			String templateKey = null;
			task.setState(Immutable.WORKFLOW_INPROCESS);
			// 插入任务后启动工作流实例
			Map<String, Object> businessData = new HashMap<>();
			if (parameterMap.containsKey("templateKey")) {
				templateKey = (String) parameterMap.get("templateKey");
				parameterMap.remove("templateKey");
			}
			if (!parameterMap.isEmpty()) {
				businessData.putAll(parameterMap);
			}
			if (StringUtils.isBlank(templateKey)) {
				templateKey = std_hazard_source_key;
			}
			businessData.put("leaderCode", signinUser.getCode());
			SafetyUser nextUser = roleService.findNextCandidate(signinUser);
			if (nextUser != null) {
				businessData.put("nextLeaderCode", nextUser.getCode());
			}
			MessageEntity<?> messageEntity = startUpFlow(templateKey, task.getTaskDesc(), "", signinUser.getCode(),
					task.getId(), businessData);
			if (messageEntity.getCode() == 0) {
				String instanceId = (String) messageEntity.getData();
				task.setFlowInstanceId(instanceId);
				safetyTaskMapper.update(task);
				return true;
			}
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return false;
	}*/


}
